//状态管理
const state = {
	version: '1.0',
	langIsOpen: false,
	userCustomIsOpen: false,
	orgTreeIsHide: false,
	orgTreeWidth: 192,
	baseUrl: '',
	isFreshCarTree: false,
	timerArr: [],
	isNextMenuShow: true, //二级菜单是否显示
	device: {
		width: null,
		height: null
	},
	breadcrumbArr: [], // 导航面包屑
	menuListArr: [], // 菜单
	includedComponents: [],
	isRouterAlive: true
}

//处理逻辑
const mutations = {
	setDevice(state, value) {
		state.device.width = value.width
		state.device.height = value.height
	},
	setNextMenuShow(state, value) {
		state.isNextMenuShow = value
	},
	setMenuListArr(state, value) {
		state.menuListArr = value
	},
	// 设置全局面包屑, 根据路由层次来区分
	setBreadcrumbArr(state, value) {
		let arr = state.breadcrumbArr

		const pathLevel = value.path.split('/')
		if(arr.length == 0) {
			state.breadcrumbArr.push(value)
		} else if(pathLevel.length <= 3) { //二级导航级别，重置

			arr = [value]
		} else if(pathLevel.length >= 4) {
			const previousLevel = state.breadcrumbArr[arr.length - 1].path.split('/')
			if(previousLevel.length >= pathLevel.length) { //上一级别 与当前路由级别等级相同时替换

				arr[arr.length - 1] = value
			} else if(previousLevel.length <= pathLevel.length) {
				arr.push(value)
			}
		}

		state.breadcrumbArr = arr
	},
	setIncludedComponents(state, value) {
		let isExist = false
		state.includedComponents.forEach(item => {
			if(item === value) {
				isExist = true
			}
		});
		!isExist ? state.includedComponents.push(value) : ''
	},
	setRouterAlive(state, value) {
		state.isRouterAlive = value
	}
}

export default {
	state,
	mutations
};